import java.util.*;

class TreeNode {
    String value;
    List<TreeNode> children;

    public TreeNode(String value) {
        this.value = value;
        this.children = new ArrayList<>();
    }
}

public class TreeBuilder {
    private static final String SEPARATOR = "-";

    public static void main(String[] args) {
        TreeNode root = new TreeNode("AAAD");
        buildTree(root, "AAAA", "AAAB", "AAAC");

        printTree(root);
    }

    public static void buildTree(TreeNode parent, String... values) {
        if (values.length == 0) {
            return;
        }

        String currentValue = values[0];
        for (int i = 1; i < values.length; i++) {
            currentValue += SEPARATOR + values[i];
        }

        TreeNode child = new TreeNode(currentValue);
        parent.children.add(child);

        buildTree(child, Arrays.copyOfRange(values, 1, values.length));
    }

    public static void printTree(TreeNode node) {
        System.out.println(node.value);
        for (TreeNode child : node.children) {
            printTree(child);
        }
    }
}
